package com.ymk.cmd;

import com.ymk.base.cmd.ACmd;
import com.ymk.base.cmd.CmdSign;
import com.ymk.base.exception.MallException;
import com.ymk.base.mybatis.Pagination;
import com.ymk.base.utlis.ParamsBuilder;
import com.ymk.bo.user.MchDeskBO;
import com.ymk.core.code.cmd.UserCmdCode;
import com.ymk.service.IMchDeskService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.servlet.http.HttpServletRequest;
import java.util.List;
import java.util.Objects;

@Service
public class MchDeskListCmd extends ACmd {

    @Override
    public CmdSign executeMop(HttpServletRequest request, CmdSign sign) throws Exception {
        CmdSign respSign = new CmdSign(sign);
        MchDeskBO reqData = super.getData(sign, MchDeskBO.class);

        ParamsBuilder paramsBuilder = ParamsBuilder.newBuild()
                .addParam("mchId", sign.getMchId())
                .addParam("status", reqData.getStatus())
                .setReturnStruct(sign.getReturnStruct());

        Pagination pagination = sign.buildPage();
        pagination.setParams(paramsBuilder.build());
        List<MchDeskBO> respDataList = this.mchDeskService.listForPage(pagination);

        respSign.setPageInfo(pagination);
        respSign.setSource(super.getSource(respDataList));

        return respSign;
    }

 @Override
 public CmdSign verify(HttpServletRequest request, CmdSign sign)throws  Exception{
     MchDeskBO reqData = super.getData(sign, MchDeskBO.class);
     if (Objects.isNull(sign.getMchId())){
         throw  new MallException("请先登录");
     }


        return null;
};
    @Override
    public String getCmdCode() {
        return UserCmdCode.MCH_DESK_LIST;
    }

    @Autowired
    private IMchDeskService mchDeskService;
}